#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#define MAXLINE 1096

static void sig_alrm(int signo);
static jmp_buf env_alarm;
int main(){
    char line[MAXLINE];
    int n;
    if(signal(SIGALRM, sig_alrm) == SIG_ERR){
        printf("signal error: %s\n", strerror(errno));
        exit(0);
    }
    if(_setjmp(env_alarm) != 0){
        printf("read time out\n");
        exit(0);
    }

    alarm(10);
    if((n = read(STDIN_FILENO, line, sizeof(line))) < 0){
        printf("read error: %s\n", strerror(errno));
        exit(0);
    }
    alarm(0);

    exit(0);
}

static void sig_alrm(int signo){
    longjmp(env_alarm, 1);
}